<template>
  <div>
    <!-- 返利池查询 -->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <FilterTables
      ref="table"
      columnsRef="wkcRebateDetailsQuery"
      :columns="columns"
      :isSelectColumn="false"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls">
        <multiuse-button size="small" type="primary" @click="addHandle()">导 出</multiuse-button>
      </template>
    </FilterTables>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { queryList, exportList } from '@/api/omFinanceP/RebateManage/RebateDetailsQuery';
import { exportExcelFile } from '@/utils';
export default {
  name: 'RebateDetailsQuery',
  mixins: [dictionary],
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchApi: queryList,
      fetchParams: {
      },
      formData: {},
      detailData: {},
      visible: false,
      isClick: false,
      handleType: ''
    };
  },
  components: {},
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    detailclose(val) {
      this.isClick = false;
    },

    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    async addHandle() {
      this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
        confirmButtonText: '下载',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          let json = this.fetchParams;
          this.exportLoading = true;
          exportList(json)
            .then(response => {
              exportExcelFile(response.data, '返利池查询');
            })
            .catch(err => {});
          this.exportLoading = false;
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
    },
    async editHandle(data, type) {
      this.detailData = data;
      this.isClick = true;
    },
    formatNumber(value) {
      value += '';
      if (value.slice(-1) === '.') return value;
      value = value.replace(/,\s+/g, '');
      const list = value.split('.');
      const prefix = list[0].charAt(0) === '-' ? '-' : '';
      let num = prefix ? list[0].slice(1) : list[0];
      let result = '';
      while (num.length > 3) {
        result = `, ${num.slice(-3)}${result}`;
        num = num.slice(0, num.length - 3);
      }
      if (num) {
        result = num + result;
      }
      return `${prefix}${result}${list[1] ? `.${list[1]}` : ''}`;
    },
    createdFrom() {
      return [
        {
          type: 'SELECT',
          label: '业务类型',
          fieldName: 'businessType',
          placeholder: '请选择',
          itemList: this.createDlrDictList('2147')
        },
        {
          type: 'INPUT',
          label: '业务单据号',
          fieldName: 'billNo',
          placeholder: '请输入'
        },
        {
          type: 'RANGE_DATE',
          label: '记账时间',
          fieldName: 'accountDateStart|accountDateEnd',
          dateType: 'exactdaterange',
          placeholder: '请选择'
        },
        {
          type: 'INPUT',
          label: '业务单据号',
          fieldName: 'new',
          placeholder: '请输入',
          hidden: true
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '经销商代码',
          width: 120,
          dataIndex: 'dealerCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '经销商名称',
          dataIndex: 'dealerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '记账时间',
          width: 180,
          dataIndex: 'accountDate',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '业务单据号',
          width: 180,
          dataIndex: 'billNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'VIN',
          width: 180,
          dataIndex: 'vin',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '业务类型',
          dataIndex: 'businessType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDlrDictList('2147'),
          render: props => {
            return <span>{this.createDlrDictText(props.row.status, '2147')}</span>;
          }
        },
        {
          title: '原金额',
          dataIndex: 'originalAmount',
          sorter: true,
          filter: true,
          precision: 2,
          numberFormat: true,
          align: 'right',
          filterType: 'input'
        },
        {
          title: '发生金额',
          dataIndex: 'chngAmount',
          sorter: true,
          filter: true,
          precision: 2,
          numberFormat: true,
          align: 'right',
          filterType: 'input'
        },
        {
          title: '账户余额',
          dataIndex: 'balanceAmount',
          sorter: true,
          filter: true,
          precision: 2,
          numberFormat: true,
          align: 'right',
          filterType: 'input'
        },
        {
          title: '备注',
          dataIndex: 'remark',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    }
  }
};
</script>
